import dash
import uuid
from dash import html, dcc
import feffery_antd_components as fac
from dash.dependencies import Input, Output, State

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        dcc.Location(id='url'),
        fac.AntdUpload(
            id='upload-button-1',
            buttonContent='上传按钮1',
            apiUrl='/upload/'
        ),
        fac.AntdUpload(
            id='upload-button-2',
            buttonContent='上传按钮2',
            apiUrl='/upload/'
        ),
        html.Div(
            id='show-upload-ids'
        )
    ],
    style={
        'padding': '50px'
    }
)


@app.callback(
    [Output('upload-button-1', 'uploadId'),
     Output('upload-button-2', 'uploadId')],
    Input('url', 'pathname')
)
def generate_upload_id(pathname):
    current_uuid = str(uuid.uuid4())
    return [
        'upload-button-1' + ' ' + current_uuid,
        'upload-button-2' + ' ' + current_uuid
    ]


@app.callback(
    Output('show-upload-ids', 'children'),
    [Input('upload-button-1', 'uploadId'),
     Input('upload-button-2', 'uploadId')]
)
def show_current_upload_id(uploadId1, uploadId2):
    return fac.AntdSpace(
        [
            fac.AntdText('upload-button-1：' + uploadId1),
            fac.AntdText('upload-button-2：' + uploadId2)
        ],
        direction='vertical'
    )


if __name__ == '__main__':
    app.run_server(debug=True)
